package com.lb.algorithm;

/**
 * @version 1.0
 * @Author: Edward
 * @Date: 2021/10/29 9:24
 * @Description: 求数组中最大值
 */
public class ArrayMax {

    public static int getMax(int[] arr) {
        return process(arr, 0, arr.length - 1);
    }

    public static int process(int[] arr, int L, int R) {
        if (L == R) {
            return arr[L];
        }

        //中点
        int mid = L + ((R - L) >> 1);
        int leftMax = process(arr, L, mid);
        int rightMax = process(arr, mid + 1, R);
        return Math.max(leftMax, rightMax);
    }

    public static void main(String[] args) {
        int[] arr = {2, 3, 5, 43, 1, 54, 21};
        System.out.println(getMax(arr));
    }
}
